﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.workers {
    import flash.utils.*;
    import __AS3__.vec.*;

    public class Workers {

        public static const NUM_PURCHASED_WORKERS:String = "numPurchasedWorkers";

        protected var m_attributes:Dictionary;
        protected var m_workers:Vector.<WorkerInfo>;

        public function Workers(){
            this.m_attributes = new Dictionary();
            this.m_workers = new Vector.<WorkerInfo>();
        }
        public function loadObject(_arg1:Object):void{
            var _local2:String;
            var _local3:Object;
            var _local4:WorkerInfo;
            for (_local2 in _arg1.attributes) {
                this.m_attributes[_local2] = _arg1.attributes[_local2];
            };
            for each (_local3 in _arg1.members) {
                _local4 = new WorkerInfo();
                _local4.loadObject(_local3);
                this.m_workers.push(_local4);
            };
        }
        public function preserveAndLoadObject(_arg1:Object):void{
            var _local2:String;
            var _local3:WorkerInfo;
            var _local4:Object;
            var _local5:Boolean;
            var _local6:WorkerInfo;
            for (_local2 in _arg1.attributes) {
                this.m_attributes[_local2] = _arg1.attributes[_local2];
            };
            for each (_local4 in _arg1.members) {
                _local3 = new WorkerInfo();
                _local3.loadObject(_local4);
                _local5 = false;
                for each (_local6 in this.m_workers) {
                    if (_local6.zid == _local3.zid){
                        _local5 = true;
                        break;
                    };
                };
                if (_local5 == false){
                    this.m_workers.push(_local3);
                };
            };
        }
        public function cleanUp(_arg1:Boolean=false):void{
            var _local2:String;
            var _local3:WorkerInfo;
            if (!_arg1){
                if (this.m_attributes){
                    for (_local2 in this.m_attributes) {
                        delete this.m_attributes[_local2];
                    };
                };
                this.m_attributes = new Dictionary();
            };
            if (this.m_workers){
                for each (_local3 in this.m_workers) {
                    if (_local3){
                        _local3.cleanUp();
                    };
                };
            };
            this.m_workers = new Vector.<WorkerInfo>();
        }
        public function doesWorkerExist(_arg1:String):Boolean{
            return ((this.getWorkerPosition(_arg1) >= 0));
        }
        public function getWorkerPosition(_arg1:String):int{
            var _local2:int;
            while (_local2 < this.m_workers.length) {
                if (((this.m_workers[_local2]) && ((this.m_workers[_local2].zid == _arg1)))){
                    return (_local2);
                };
                _local2++;
            };
            return (-1);
        }
        public function canAddWorker(_arg1:String=null, _arg2:Boolean=false):Boolean{
            if (this.getRemainingSpots() > 0){
                if (((_arg1) && (!(_arg2)))){
                    return (!(this.doesWorkerExist(_arg1)));
                };
                return (true);
            };
            return (false);
        }
        public function addWorker(_arg1:String, _arg2:Boolean=false):int{
            var _local4:WorkerInfo;
            var _local3 = -1;
            if (this.canAddWorker(_arg1, _arg2)){
                _local4 = new WorkerInfo(_arg1);
                this.m_workers.push(_local4);
                _local3 = (this.m_workers.length - 1);
            };
            return (_local3);
        }
        public function removeWorkerById(_arg1:String, _arg2:Boolean=true):Boolean{
            var _local3:int = this.getWorkerPosition(_arg1);
            return (this.removeWorkerByPosition(_local3, _arg2));
        }
        public function removeWorkerByPosition(_arg1:int, _arg2:Boolean=true):Boolean{
            if (_arg1 >= this.m_workers.length){
                return (false);
            };
            if (_arg2){
                this.m_workers.splice(_arg1, 1);
            } else {
                this.m_workers[_arg1] = null;
            };
            return (true);
        }
        public function getRemainingSpots():int{
            var _local1:int = this.getWorkerCount();
            return (Math.max((this.maxWorkers - _local1), 0));
        }
        public function getWorkerCount(_arg1:Function=null):int{
            var _local3:Vector.<String>;
            var _local2:int;
            if (_arg1 == null){
                _local2 = this.m_workers.length;
            } else {
                _local3 = this.getWorkerIds(_arg1);
                _local2 = _local3.length;
            };
            return (_local2);
        }
        public function getWorkerIds(_arg1:Function=null):Vector.<String>{
            var _local3:WorkerInfo;
            var _local2:Vector.<String> = new Vector.<String>();
            for each (_local3 in this.m_workers) {
                if (((_local3) && ((((_arg1 == null)) || (_arg1(_local3.zid, _local3.data)))))){
                    _local2.push(_local3.zid);
                };
            };
            return (_local2);
        }
        public function purgeWorkers(_arg1:Function=null):void{
            var _local3:WorkerInfo;
            var _local2:int = (this.m_workers.length - 1);
            while (_local2 >= 0) {
                _local3 = this.m_workers[_local2];
                if (((((!(_local3)) || ((_arg1 == null)))) || (_arg1(_local3.zid, _local3.data)))){
                    this.m_workers.splice(_local2, 1);
                };
                _local2--;
            };
        }
        public function get maxWorkers():int{
            return (0);
        }
        public function get numPurchasedWorkers():int{
            return (this.getAttribute(NUM_PURCHASED_WORKERS, 0));
        }
        public function set numPurchasedWorkers(_arg1:int):void{
            this.setAttribute(NUM_PURCHASED_WORKERS, _arg1);
        }
        protected function getAttribute(_arg1:String, _arg2){
            var _local3:* = _arg2;
            if (this.m_attributes.hasOwnProperty(_arg1)){
                _local3 = this.m_attributes[_arg1];
            };
            return (_local3);
        }
        protected function setAttribute(_arg1:String, _arg2):void{
            this.m_attributes[_arg1] = _arg2;
        }
        protected function getWorkerData(_arg1:int, _arg2:String, _arg3){
            var _local4:* = _arg3;
            if ((((_arg1 < this.m_workers.length)) && (!((this.m_workers[_arg1] == null))))){
                if (this.m_workers[_arg1].data.hasOwnProperty(_arg2)){
                    _local4 = this.m_workers[_arg1].data[_arg2];
                };
            };
            return (_local4);
        }
        protected function setWorkerData(_arg1:int, _arg2:String, _arg3):Boolean{
            var _local4:Boolean;
            if ((((_arg1 < this.m_workers.length)) && (!((this.m_workers[_arg1] == null))))){
                this.m_workers[_arg1].data[_arg2] = _arg3;
                _local4 = true;
            };
            return (_local4);
        }
        protected function getAllWorkerData(_arg1:int, _arg2):Dictionary{
            var _local3:* = _arg2;
            if ((((_arg1 < this.m_workers.length)) && (!((this.m_workers[_arg1] == null))))){
                _local3 = this.m_workers[_arg1].data;
            };
            return (_local3);
        }
        protected function setAllWorkerData(_arg1:int, _arg2:Dictionary):void{
            if ((((_arg1 < this.m_workers.length)) && (!((this.m_workers[_arg1] == null))))){
                this.m_workers[_arg1].data = _arg2;
            };
        }
        public function getRawAttributes():Object{
            var _local2:String;
            var _local1:Object = {};
            for (_local2 in this.m_attributes) {
                _local1[_local2] = this.m_attributes[_local2];
            };
            return (_local1);
        }

    }
}//package Modules.workers 

import flash.utils.*;

class WorkerInfo {

    public var zid:String;
    public var data:Dictionary;

    public function WorkerInfo(_arg1:String=""){
        this.zid = _arg1;
        this.data = new Dictionary();
    }
    public function loadObject(_arg1:Object):void{
        var _local2:String;
        this.zid = _arg1.zid;
        for (_local2 in _arg1.data) {
            this.data[_local2] = _arg1.data[_local2];
        };
    }
    public function cleanUp():void{
        var _local1:String;
        this.zid = "";
        for (_local1 in this.data) {
            delete this.data[_local1];
        };
        this.data = new Dictionary();
    }

}
